I'm sure it's simple but I can't find the answer so I'm hoping someone can help.
string strValues[] = {"CAT", "DOG"}
string strValues[] = {"CAT", "DOG", "MOUSE", "DUCK"}
Martin_Hunter - Wed Nov 23 11:33:59 EST 2011 |
Re: Update string array |
Re: Update string array Typically you will have a fixed number of columns and add rows dynamically. Typically also you have a sibling Skip list you use to index things in your Array; which is far faster than searching of it. There is some way to use a string "Array" as a character "array" but I don't know about that.
|
Re: Update string array
If you know the max size of the string array you could just prefill it with empty strings. The following would first print:
int i
string strValues[] = {"CAT", "DOG", "", ""}
for i in 0 : 3 by 1 do
{
print strValues[i] "\n"
}
strValues[2] = "MOUSE"
strValues[3] = "DUCK"
for i in 0 : 3 by 1 do
{
print strValues[i] "\n"
}
|
Re: Update string array LindyEd - Wed Nov 23 13:50:25 EST 2011
If you know the max size of the string array you could just prefill it with empty strings. The following would first print:
int i
string strValues[] = {"CAT", "DOG", "", ""}
for i in 0 : 3 by 1 do
{
print strValues[i] "\n"
}
strValues[2] = "MOUSE"
strValues[3] = "DUCK"
for i in 0 : 3 by 1 do
{
print strValues[i] "\n"
}
Just to expand on Lindy's post, if you need a very large number just throw in an array size. Then maybe also keep an integer representing the number of valid entries in the array. string strValues[100] int strValuesSize = 0
void add(string strValue)
{
strValues[strValuesSize++] = strValue
}
void remove(int index)
{
int i
for (i = index + 1; i < strValuesSize; i++)
{
strValues[i - 1] = strValues[i]
}
strValuesSize--
}
void printAll(void)
{
int i
for (i = 0; i < strValuesSize; i++)
{
print strValues[i] "\n"
}
}
add("CAT")
add("DOG")
printAll()
add("MOUSE")
add("DUCK")
printAll()
|
Re: Update string array I also found out that once a string array is defined it cannot be overwritten or deleted! |